package com.zz.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.zz.entity.ConsumeLogs;
import com.zz.entity.GetStatistics;

public interface ConsumeLogsDao extends JpaRepository<ConsumeLogs, Integer>,JpaSpecificationExecutor<ConsumeLogs> {
	
	
	/** 
	 * 自定义查询
	 */
	//查询当天的资源使用总数
	@Query( value = "select count(*),Read_room_id FROM consumelogs where In_time > ?1 and Out_time < ?2 GROUP BY Read_room_id" , nativeQuery = true)
	List<GetStatistics> getTheDateCount(String indate,String outdate);
	
	//添加打卡信息
	@Transactional
	@Modifying
	@Query(value="insert into consumelogs(status,Card_no,In_time,Out_time,Read_room_id,read_room_ids) value(:#{#con.Status},:#{#con.CardNo},:#{#con.InTime},:#{#con.OutTime},:#{#con.ReadRoomId},:#{#con.ReadRoomId})",nativeQuery = true )
	Integer saveAndFlushConsumeLogs(ConsumeLogs con);
}
